/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package adventure_game;

import java.util.Scanner;

/**
 * Gets inputs from player, and activates the commandword.
 * @author Frank, Morten B, Ronni
 */

public class Parser
{
    private CommandWords commands;  // Contains the Command words.
    private Scanner reader;         // Reads the players commands.

    /**
     * Create a parser to read from the terminal window.
     */
    public Parser(Scanner reader)
    {
        commands = new CommandWords();
        this.reader = reader;
    }

    /**
     *  Register 2 words that player types in.
     * @Returns the players next command.
     */
    public Command getCommand()
    {
        String inputLine;
        String word1 = null;
        String word2 = null;

        inputLine = reader.nextLine();
       
        Scanner tokenizer = new Scanner(inputLine);
        if (tokenizer.hasNext())
        {
            word1 = tokenizer.next();
            if (tokenizer.hasNext())
            {
                word2 = tokenizer.next();
            }
        }
        return new Command(commands.getCommandWord(word1), word2);
    }

    /**
     * Prints the usable command words.
     */
    public void showCommands()
    {
        commands.showAll();
    }
}
